Why does it not allowed to use try-catch statement without {} ?

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-05-06T13:25:46Z Indexed on 2010/05/06 13:28 UTC
Read the original article Hit count: 228

Filed under:

Why can't I use code like this ?

1

int i = 0;

try i = int.Parse("qwerty");
catch throw;

2

try i = int.Parse("qwerty");
catch;
finally Log.Write("error");

And should write like this

1

int i = 0;

try { i = int.Parse("qwerty"); } catch { throw; }

2

try { i = int.Parse("qwerty");}
catch {}
finally {Log.Write("error");}

PS:

I can use if-else statement without {}. Why should I use them with try-catch(-finally) statement ? Is there any meaningful reason ?

Is it only because that some people think that code is hard to read ?

Several months ago I asked that question on russian programming forum but I got no satisfactory answer ...

© Stack Overflow or respective owner

Related posts about c#